<?php
function check(){
    if($_FILES['image']['error']){
        switch($_FILES['image']['error']){
            case 1:
                return "文件大小超过了php.ini中允许的最大值";
            case 2:
                return "文件大小超过了表单允许的最大值";
            case 3:
                return "只有部分文件上传";
            case 4:
                return "没有文件上传";
            case 6:
                return "找不到临时文件";
            case 7:
                return "文件写入失败";
        }
    }
    $allow=array('image/jpeg','image/png','image/gif');
    $info=finfo_open(FILEINFO_MIME_TYPE);
    $min=finfo_file($info,$_FILES['image']['tmp_name']);
    return in_array($min,$allow)?"":"只能上传'{$allow}的格式文件";
}
//3.验证大小
$size=12345;
// $k=1024;
// var_dump($_FILES);
if(!empty($_POST)){
    echo check();
}
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="" enctype="multipart/form-data">
        <input type="file" name="image">
        <input type="submit" value="上传">
    </form>
</body>
</html>